home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1UYAKH3 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  5.7 KB  |  172 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import java.awt.AWTEvent;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Frame;
  9. import java.awt.Graphics;
  10. import java.awt.LayoutManager;
  11. import java.awt.event.InputEvent;
  12. import java.awt.event.KeyEvent;
  13. import java.awt.event.WindowEvent;
  14. import java.util.Vector;
  15.  
  16. public class JFrame extends Frame implements WindowConstants, Accessible, RootPaneContainer {
  17.    private int defaultCloseOperation = 1;
  18.    protected JRootPane rootPane;
  19.    protected boolean rootPaneCheckingEnabled = false;
  20.    protected AccessibleContext accessibleContext = null;
  21.  
  22.    public JFrame() {
  23.       this.frameInit();
  24.    }
  25.  
  26.    public JFrame(String title) {
  27.       super(title);
  28.       this.frameInit();
  29.    }
  30.  
  31.    protected void addImpl(Component comp, Object constraints, int index) {
  32.       if (this.isRootPaneCheckingEnabled()) {
  33.          throw this.createRootPaneException("add");
  34.       } else {
  35.          super.addImpl(comp, constraints, index);
  36.       }
  37.    }
  38.  
  39.    protected JRootPane createRootPane() {
  40.       return new JRootPane();
  41.    }
  42.  
  43.    private Error createRootPaneException(String op) {
  44.       String type = this.getClass().getName();
  45.       return new Error("Do not use " + type + "." + op + "() use " + type + ".getContentPane()." + op + "() instead");
  46.    }
  47.  
  48.    protected void frameInit() {
  49.       ((Component)this).enableEvents(72L);
  50.       this.setRootPane(this.createRootPane());
  51.       ((Component)this).setBackground(UIManager.getColor("control"));
  52.       this.setRootPaneCheckingEnabled(true);
  53.    }
  54.  
  55.    public AccessibleContext getAccessibleContext() {
  56.       if (this.accessibleContext == null) {
  57.          this.accessibleContext = new AccessibleJFrame(this);
  58.       }
  59.  
  60.       return this.accessibleContext;
  61.    }
  62.  
  63.    public Container getContentPane() {
  64.       return this.getRootPane().getContentPane();
  65.    }
  66.  
  67.    public int getDefaultCloseOperation() {
  68.       return this.defaultCloseOperation;
  69.    }
  70.  
  71.    public Component getGlassPane() {
  72.       return this.getRootPane().getGlassPane();
  73.    }
  74.  
  75.    public JMenuBar getJMenuBar() {
  76.       return this.getRootPane().getMenuBar();
  77.    }
  78.  
  79.    public JLayeredPane getLayeredPane() {
  80.       return this.getRootPane().getLayeredPane();
  81.    }
  82.  
  83.    public JRootPane getRootPane() {
  84.       return this.rootPane;
  85.    }
  86.  
  87.    protected boolean isRootPaneCheckingEnabled() {
  88.       return this.rootPaneCheckingEnabled;
  89.    }
  90.  
  91.    protected void processKeyEvent(KeyEvent e) {
  92.       super.processKeyEvent(e);
  93.       if (!((InputEvent)e).isConsumed()) {
  94.          JComponent.processKeyBindingsForAllComponents(e, this, new Vector(), ((AWTEvent)e).getID() == 401);
  95.       }
  96.  
  97.    }
  98.  
  99.    protected void processWindowEvent(WindowEvent e) {
  100.       super.processWindowEvent(e);
  101.       if (((AWTEvent)e).getID() == 201) {
  102.          switch (this.defaultCloseOperation) {
  103.             case 0:
  104.             default:
  105.                break;
  106.             case 1:
  107.                ((Component)this).setVisible(false);
  108.                break;
  109.             case 2:
  110.                ((Component)this).setVisible(false);
  111.                ((Frame)this).dispose();
  112.          }
  113.       }
  114.  
  115.    }
  116.  
  117.    public void setContentPane(Container contentPane) {
  118.       this.getRootPane().setContentPane(contentPane);
  119.    }
  120.  
  121.    public void setDefaultCloseOperation(int operation) {
  122.       this.defaultCloseOperation = operation;
  123.    }
  124.  
  125.    public void setGlassPane(Component glassPane) {
  126.       this.getRootPane().setGlassPane(glassPane);
  127.    }
  128.  
  129.    public void setJMenuBar(JMenuBar menubar) {
  130.       this.getRootPane().setMenuBar(menubar);
  131.    }
  132.  
  133.    public void setLayeredPane(JLayeredPane layeredPane) {
  134.       this.getRootPane().setLayeredPane(layeredPane);
  135.    }
  136.  
  137.    public void setLayout(LayoutManager manager) {
  138.       if (this.isRootPaneCheckingEnabled()) {
  139.          throw this.createRootPaneException("setLayout");
  140.       } else {
  141.          super.setLayout(manager);
  142.       }
  143.    }
  144.  
  145.    protected void setRootPane(JRootPane root) {
  146.       if (this.rootPane != null) {
  147.          ((Container)this).remove(this.rootPane);
  148.       }
  149.  
  150.       this.rootPane = root;
  151.       if (this.rootPane != null) {
  152.          boolean checkingEnabled = this.isRootPaneCheckingEnabled();
  153.  
  154.          try {
  155.             this.setRootPaneCheckingEnabled(false);
  156.             ((Container)this).add(this.rootPane, "Center");
  157.          } finally {
  158.             this.setRootPaneCheckingEnabled(checkingEnabled);
  159.          }
  160.       }
  161.  
  162.    }
  163.  
  164.    protected void setRootPaneCheckingEnabled(boolean enabled) {
  165.       this.rootPaneCheckingEnabled = enabled;
  166.    }
  167.  
  168.    public void update(Graphics g) {
  169.       ((Container)this).paint(g);
  170.    }
  171. }
  172.